function alloc_groups(glist,ng)
  use global_param,only:n_point_type
  use group_param,only:n_object_group
  use group_param,only:object_group
  implicit none

  interface
     function reallocInt(p,n)
       integer,pointer,dimension(:) :: &
            reallocInt,p
       integer,intent(in) :: n
     end function reallocInt
  end interface
  
  integer,pointer,dimension(:) :: alloc_groups
  integer,pointer,dimension(:) :: glist
  integer,intent(out) :: ng

  integer :: i,j,n,foo

  ng=0

  nullify(alloc_groups)

  do i=1,n_object_group
     select case(object_group(i)%group_type)
     case(1)
        ! Configuration
        foo=0
        do j=1,object_group(i)%n_point
           n=object_group(i)%point_type(j)
           if (object_group(i)%min_size(j).lt.0) then
              ! -nn
              if (glist(n).gt.0.and.&
                   glist(n).le.object_group(i)%max_size(j)) &
                   foo=foo+1
           else if (object_group(i)%max_size(j).lt.0) then
              ! nn-
              if (glist(n).ge.object_group(i)%min_size(j)) &
                   foo=foo+1
           else
              ! nn-nn
              if (glist(n).ge.object_group(i)%min_size(j).and.&
                   glist(n).le.object_group(i)%max_size(j)) foo=foo+1
           end if
        end do
        if (foo.eq.object_group(i)%n_point) then
           ng=ng+1
           alloc_groups=>reallocInt(alloc_groups,ng)
           alloc_groups(ng)=i
        end if
     case(2)
        ! Total size
        n=0
        do j=1,n_point_type
           n=n+glist(j)
        end do
        foo=0
        if (object_group(i)%min_size(1).lt.0) then
           if (n.gt.0.and.&
                n.le.object_group(i)%max_size(1)) foo=foo+1
        else if (object_group(i)%max_size(1).lt.0) then
           if (n.ge.object_group(i)%min_size(1)) foo=foo+1
        else
           if (n.le.object_group(i)%max_size(1).and.&
                n.ge.object_group(i)%min_size(1)) foo=foo+1
        end if
        if (foo.eq.1) then
           ng=ng+1
           alloc_groups=>reallocInt(alloc_groups,ng)
           alloc_groups(ng)=i
        end if
     case(3)
        ! Inclusion of one type
        n=object_group(i)%point_type(1)
        if (glist(n).gt.0) then
           ng=ng+1
           alloc_groups=>reallocInt(alloc_groups,ng)
           alloc_groups(ng)=i
        end if
     end select
  end do

  return

end function alloc_groups
